package com.wteam.dragon.system.apps.generator.pojo.bean;

import com.baomidou.mybatisplus.annotation.*;
import com.gitee.sunchenbin.mybatis.actable.annotation.*;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import com.wteam.dragon.system.apps.generator.util.GenUtil;
import com.wteam.dragon.system.basebean.bean.BaseBean;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * @Author 陈晓辉
 * @Date 2021/5/29 8:43
 */

@Data
@Table
@TableName
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class ColumnInfo extends BaseBean {
    @IsKey
    @IsNotNull
    @IsAutoIncrement
    @TableId(type = IdType.AUTO)
    @ColumnType(MySqlTypeConstant.BIGINT)
    @Column(comment = "自增id")
    private Long id;

    @IsNotNull
    @Column(comment = "表名")
    @ColumnType(MySqlTypeConstant.VARCHAR)
    private String tableName;

    @IsNotNull
    @Column(comment = "数据库字段名称")
    @ColumnType(MySqlTypeConstant.VARCHAR)
    private String columnName;

    @IsNotNull
    @Column(comment = "数据库字段类型")
    @ColumnType(MySqlTypeConstant.VARCHAR)
    private String columnType;

    @IsNotNull
    @Column(comment = "数据库字段键类型")
    @ColumnType(MySqlTypeConstant.VARCHAR)
    private String keyType;

    @Column(comment = "字段额外的参数")
    @ColumnType(MySqlTypeConstant.VARCHAR)
    private String extra;

    @Column(comment = "数据库字段描述")
    @ColumnType(MySqlTypeConstant.VARCHAR)
    private String remark;

    @Column(comment = "是否必填")
    @ColumnType(MySqlTypeConstant.TINYINT)
    private Boolean notNull;

    @Column(comment = "查询类型")
    @ColumnType(MySqlTypeConstant.VARCHAR)
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String queryType;

    @Column(comment = "排序类型")
    @ColumnType(MySqlTypeConstant.VARCHAR)
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String orderType;

    public ColumnInfo(String tableName, String columnName, Boolean notNull, String columnType, String remark, String keyType, String extra) {
        this.tableName = tableName;
        this.columnName = columnName;
        this.columnType = columnType;
        this.keyType = keyType;
        this.extra = extra;
        this.notNull = notNull;
        if(GenUtil.PK.equalsIgnoreCase(keyType) && GenUtil.EXTRA.equalsIgnoreCase(extra)){
            this.notNull = false;
        }
        this.remark = remark;
    }
}
